package com.cmbc.bean;

import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * @author jianghaoqiang
 * @Date 2022/5/22
 * 4.通过beandefintion来定义bean
 */
public class CreateByBeanDefinitionTest {
    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext =new AnnotationConfigApplicationContext();
        AbstractBeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition().getBeanDefinition();
        beanDefinition.setBeanClass(User.class);
        applicationContext.registerBeanDefinition("user",beanDefinition);
        applicationContext.refresh();
        User user=applicationContext.getBean("user",User.class);
        System.out.println(user);
    }
}
